#ifndef JSERIALPORT_H
#define JSERIALPORT_H

#include <JXQIO/JBus>

namespace JXQ
{

class JSerialPortPrivate;

class JXQLIB_EXPORT JSerialPort : public JBus
{
public:
	JSerialPort();
	explicit JSerialPort(const JString &comName);
	~JSerialPort();

public:
	enum: uint32_t
	{
		BR_50 = 50, BR_75 = 75,
		BR_110 = 110, BR_150 = 150, BR_200 = 200, BR_300 = 300, BR_600 = 600,
		BR_1200 = 1200, BR_1800 = 1800, BR_2400 = 2400, BR_4800 = 4800, BR_9600 = 9600,
		BR_19200 = 19200, BR_38400 = 38400, BR_57600 = 57600,
		BR_115200 = 115200
	};

	void setBaudRate(uint32_t baudRate);
	uint32_t baudRate() const;

public:
	enum StopBit {
		SB_1Bit, SB_1p5Bit, SB_2Bit,
	};
	void setStopBit(StopBit sb);
	StopBit stopBit() const;

public:
	enum CheckMode {
		CM_None, CM_Odd, CM_Even, CM_SPACE
	};
	void setCheckMode(CheckMode mode);
	CheckMode checkMode() const;

public:
	enum DataBitsType {
		DBT_5 = 5, DBT_6, DBT_7, DBT_8
	};
	void setDataBitsType(DataBitsType type);
	DataBitsType setDataBitsType() const;

public:
	enum FlowType {
		Flow_Off, Flow_Hardware, Flow_XonxOff
	};
	void setFlowControl(FlowType type);
	FlowType flowControl() const;

public:
	bool open(OpenMode mode) override;
	bool open(int handle, OpenMode mode) override;
	bool open(const FILE *fsp, OpenMode mode) override;

private:
	J_DISABLE_COPY(JSerialPort)
	JSerialPortPrivate *d_ptr;
};

} //namespace JXQ


#endif //JSERIALPORT_H
